package com.atguigu.gmall.wms.mapper;

import com.atguigu.gmall.wms.entity.WareEntity;
import com.atguigu.gmall.wms.entity.WareSkuEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 商品库存
 * 
 * @author rhine
 * @email gangge@atguigu.com
 * @date 2022-04-21 11:02:09
 */
@Mapper
public interface WareSkuMapper extends BaseMapper<WareSkuEntity> {

    //查询剩余库存
    @Select("SELECT * from wms_ware_sku WHERE sku_id = #{skuId} AND stock - stock_locked >= #{count}")//和在mapper.xml文件里面写的效果是一样的
    List<WareSkuEntity> checkStock(@Param("skuId")Long skuId, @Param("count")Integer count);

    //锁定库存
    @Update("UPDATE wms_ware_sku SET stock_locked = stock_locked - #{count}  WHERE id = #{id}  ")
    boolean lockStock(@Param("id")Long id, @Param("count")Integer count);

    //解锁库存
    @Update("UPDATE wms_ware_sku SET stock_locked = stock_locked + #{count}  WHERE id = #{id}  ")
    boolean unlockedStock(@Param("id")Long id,@Param("count")Integer count);

}
